//
//  main.m
//  Day5homework
//
//  Created by dllo on 16/5/7.
//  Copyright © 2016年 lanou. All rights reserved.
//
#include <stdio.h>
//  #import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    // 第一题
    /*
    int a[9] = {0};
    int i = 0;
    for(i = 0; i < 9; i++)
    {
        a[i] = i + 10;
        printf("a[%d] = %d\n", i, a[i]);
    }
     */
    
    // 第二题 将第一题中的数组a反向输出
    /*
    int a[9] = {0};
    int i = 0;
    for(i = 8; i >= 0; i--){
        a[i] = i + 10;
        printf("a[%d] = %d\n", i, a[i]);
    }
    */
    
    // 第三题 对第一题中的数组进行求和操作,打印计算结果
    /*
    int a[9] = {0};
    int i = 0;
    int sum = 0;
    for(i = 0; i < 9; i++)
    {
        a[i] = i + 10;
        sum += a[i];
        printf("a[%d] = %d\n", i, a[i]);
    }
    printf("数组元素的和为:%d", sum);
    return 0;
     */
    
    // 第四题 计算第一题数组连减,打印计算结果
    /*
    int a[9] = {0};
    int i = 0;
    int sum = 0;
    for (i = 0; i < 9; i++) {
        a[i] = i + 10;
        sum -= a[i];
    }
    printf("连减结果%d\n", sum);
     */
    
    // 第五题 随机产生20个10~50的正整数存放到数组中,并求数组中的 最大值,最小值,平均值及各个元素之和
    // printf("%d", arc4random() % (50 - 10 + 1) + 10); //随机数
    /*
    int z[20] = {0};
    int i = 0;
    for (i = 0; i < 20; i++) {
        z[i] = arc4random() % (50 - 10 + 1) + 10;
    }
    int j = 0;
    int max = 0;
    int min = 50;
    int sum = 0;
    double pj = 0.0;
    for (j = 0; j < 20; j++) {
        max = max > z[j] ? max : z[j];
        min = min < z[j] ? min : z[j];
        sum += z[j];
    }
    pj = sum / 20.00;
    printf("最大值为:%d\n最小值为:%d\n和为:%d\n平均值为:%.2lf\n", max, min, sum, pj);
    
    */
    
    // 第六题 编写一个程序,输入两个包含5个元素的数组,先将两个数组 升序排列,然后将这两个数组合并成一个升序数组
    
    int a[5] = { 9, 7, 5, 3, 1};
    int b[5] = { 8, 4, 6 ,2, 10};
    int c[10] = {0};
    
    int i, j, temp;
    //a的冒泡排序
    for (i = 0; i < 5 - 1; i++) {
        for (j = 0; j < 5 - 1 - i; j++) {
            if (a[j] > a[j + 1]) {
                temp = a[j];
                a[j] = a[j + 1];
                a[j + 1] = temp;
            }
        }
    }
    //b的冒泡排序
    for (i = 0; i < 5 - 1; i++) {
        for (j = 0; j < 5 - 1 - i; j++) {
            if (b[j] > b[j + 1]) {
                temp = b[j];
                b[j] = b[j + 1];
                b[j + 1] = temp;
            }
        }
    }
    // 将ab数组组合为c数组
    for (i = 0; i < 5 ; i++) {
        c[i] = a[i];
    }
    
    for (i = 9; i > 4 ; i--) {
        c[i] = b[i - 5];
    }
    //将新的c数组冒泡排序
    for (i = 0; i < 10 - 1; i++) {
        for (j = 0; j < 10 - 1 - i; j++) {
            if (c[j] > c[j + 1]) {
                temp = c[j];
                c[j] = c[j + 1];
                c[j + 1] = temp;
            }
        }
    }
        
        
        
    int x = 0;
    for (x = 0; x < 5; x++) {
        printf("%d,", a[x]);
    }
    printf("\n");
    for (x = 0; x < 5; x++) {
        printf("%d,", b[x]);
    }
    printf("\n");
    for (x = 0; x < 10; x++) {
        printf("%d,", c[x]);
    }
    
    
    // 第七题 给定某年某月某日,输出其为这一年的第几天
   
    int year = 0;
    int month = 0;
    int day = 0;
    int ping[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int today = 0;
    printf("请输入年月日,中间用逗号分隔\n");
    scanf("%d,%d,%d", &year, &month, &day);
    for (int i = 0; i < month - 1 ; i++){
        if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
            ping[1] = 29;
        }
        today += ping[i];
    }
    today += day;
    printf("%d年%d月%d日是这年的第%d天\n", year, month, day, today);
     
    
    // 第八题 编写整型数组排序程序(冒泡排序-升序)
    
    
    
    
    // 第九题 找出下列整型数组中的最大和最小值及其所在位置的下标i
    // int a[] = {5, -9, 32, 77, 64, -24, 14, 0, 21, 45};
    
    /*
    int a[] = {5, -9, 32, 77, 64, -24, 14, 0, 21, 45};
    int b[10] = {0};
    for (int i = 0; i < 10; i++) {
        b[i] = a[i];
    }
    int len =(int)sizeof(b) / sizeof(b[0]);
    mao_pao(b, len);
    for (int i = 0; i < len; i++) {
        if(a[i] == b[0]) {
            printf("最小值的下标为:%d\n", i);
        }
        if (a[i] == b[len - 1]) {
            printf("最大值的下标为:%d\n", i);
        }
    }
     */
    
    // 第十题 把 str1, str2, str3 合并到 result 数组中。
//    char result[50] = {0};
//    char str1[] = "Lanou ";
//    char str2[] = "23_class ";
//    char str3[] = " is niu best!";
//    结果:“Lanou 23_class is niu best!”
    /*
    char result[50] = {0};
    char str1[] = "Lanou ";
    char str2[] = "23_class ";
    char str3[] = "is niu best!";
    
    strcat(result, str1);
    strcat(result, str2);
    strcat(result, str3);
    printf("%s\n", result);
    
    */
    
    
    
    
}
/*

int mao_pao(int arr[],int len) {
    int i, j, temp;
    for (i = 0; i < len - 1; i++) {
        for (j = 0; j < len - 1 - i; j++){
            if (arr[j] > arr[j + 1]) {
                temp = arr[j + 1];
                arr[j + 1] = arr[j];
                arr[j] = temp;
            }
        }
    }
    return 0;
}
*/
